#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e9+7;
const int N=1e5+5;
ll n,m,T,len,vv,d[N],v[N],a[N],p[N],sum;
ll st[N],ed[N],tag[N];
set<pair<ll,ll>> s;
set<ll> cov;
vector<ll> vec[N],lf[N];
void make1(ll pl){  //a=0
    if(v[pl]>vv){
        auto ii=s.lower_bound(make_pair(d[pl],0));
        if((*ii).second<=m){
            sum++;
            st[pl]=(*ii).second;
            ed[pl]=m;}}
    return ;}
void make2(ll pl){  //a>0
    auto ii=s.lower_bound(make_pair(d[pl],0));
    if((*ii).first==maxn)return ;
    if(v[pl]>vv){
        sum++;
        st[pl]=(*ii).second;
        ed[pl]=m;
        return ;}
    ll l=(*ii).second,r=m,res=m+1;
    while(l<=r){
        ll mid=(l+r)>>1;
        if(vv*vv-v[pl]*v[pl]<(ll)2*a[pl]*(p[mid]-d[pl])){
            res=mid;
            r=mid-1;}
        else{
            l=mid+1;}}
    if(res<=m){
        sum++;
        st[pl]=res;
        ed[pl]=m;}
    return ;}
void make3(ll pl){  //a<0
    if(v[pl]<=vv){
        return ;}
    auto ii=s.lower_bound(make_pair(d[pl],0));
    if((*ii).first==maxn)return ;
    ll l=(*ii).second,r=m,res=0;
    while(l<=r){
        ll mid=(l+r)>>1;
    //    cout<<mid<<' '<<vv*vv-v[pl]*v[pl]<<' '<<2*a[pl]*(p[mid]-d[pl])<<endl;
        if(vv*vv-v[pl]*v[pl]>=(ll)2*a[pl]*(p[mid]-d[pl])){
            r=mid-1;}
        else{
            res=mid;
            l=mid+1;}}
    if(res==0)return ;
    sum++;
    st[pl]=(*ii).second;
    ed[pl]=res;
    return ;}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        scanf("%lld %lld %lld %lld",&n,&m,&len,&vv);
        memset(st,0,sizeof(st));
        memset(ed,0,sizeof(ed));
        memset(tag,0,sizeof(tag));
        s.clear();
        cov.clear();
        sum=0;
        for(int i=0;i<=m+1;i++){
            vec[i].clear();
            lf[i].clear();}
        for(int i=1;i<=n;i++){
            scanf("%lld %lld %lld",&d[i],&v[i],&a[i]);}
        for(int i=1;i<=m;i++){
            scanf("%lld",&p[i]);
            s.insert(make_pair(p[i],i));}
        s.insert(make_pair(maxn,m+1));
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                make1(i);}
            else if(a[i]>0){
                make2(i);}
            else{
                make3(i);}}
        for(int i=1;i<=n;i++){
         //   cout<<st[i]<<' '<<ed[i]<<endl;
            vec[ed[i]].push_back(i);
            lf[st[i]].push_back(i);}
        ll ans=m;
        for(int i=1;i<=m;i++){
            for(int j=0;j<(int)lf[i].size();j++){
                cov.insert(lf[i][j]);}
            if(vec[i].size()==0)continue;
            int ok=1;
            for(int j=0;j<(int)vec[i].size();j++){
                if(!tag[vec[i][j]]){
                    ok=0;
                    break;}}
            if(ok)continue;
        //    cout<<i<<endl;
            ans--;
            for(int j:cov){
                tag[j]=1;}
            cov.clear();}
        printf("%lld %lld\n",sum,ans);}
    return 0;
}